<template>
  <div>
    <div class="topheader">
      <div class="img">
        <img :src="playlist.coverImgUrl" alt="" />
      </div>
      <div class="title">{{ playlist.name }}</div>
      <div class="button" @click="$router.push('/rank')">
        <span class="iconfont icon-zuojiantou"></span>
        {{ playlist.tags[0] || "排行榜" }}
      </div>
    </div>

    <dl class="musicList">
      <dt>
        <i class="iconfont icon-bofang"></i>播放全部<span
          >(共{{ playlist.tracks.length }}首)</span
        >
      </dt>

      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
           <dd
        v-for="(item, index) in playlist.tracks.slice(0,songlistLength)"
        :key="item.id"
        @click="setId(item.id)"
      >
        <h1>{{ index + 1 }}</h1>
        <div class="info">
          <h2>{{ item.name }}</h2>
          <h3>
            <span v-for="value in item.ar" :key="value.id"
              >{{ value.name }}&nbsp;</span
            >
          </h3>
        </div>
        <div class="redPlay"  :class="[{animationRunning:iconplay}]" v-show="playerId == item.id" >
          <div class="short"></div>
          <div class="middle"></div>
          <div class="long"></div>
        </div>
      </dd>
        </van-list>
      </van-pull-refresh>

     
    </dl>
  </div>
</template>

<script>
import { getPlaylistDetail } from "../../api/rank";
export default {
  props:["iconplay","playerId"],
  data() {
    return {
      playlist: {
        coverImgUrl: "",
        tags: [""],
        tracks: [],
      },

      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      L:1,
    };
  },
  methods: {
    setId(id) {
      // 播放全部歌曲
      this.$emit("get-play-all-id", this.$route.query.id); //传递歌单id
      this.$emit("get-player-id", id);
    },

    onLoad() {
      let that = this;
      setTimeout(() => {
        that.L +=1
        that.loading = false;
        if (that.playlist.tracks.length <= that.L*10) {
          that.finished = true;
          console.log(11112222);
        }
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
  },
  computed:{
    songlistLength(){
      return this.L * 15
    }
  },
  created() {
    
    
    let queryId = this.$route.query;
    if (!("id" in queryId)) {
      this.$router.push("/rank");
    }

    getPlaylistDetail({ id: queryId.id }).then((data) => {
      console.log(data);
      this.playlist = data.playlist;
    });
  },
};
</script>

<style lang="less">
@keyframes playNow {
  from {
    height: 30px;
  }
  to {
    height: 5px;
  }
}
.topheader {
  position: relative;
  height: 270px;
  .img {
    background-color: aqua;
    width: 100%;
    height: 270px;
    position: relative;
    img {
      position: absolute;
      top: 0px;
      left: 0px;
      right: 0px;
      bottom: 0px;
      margin: auto;
      width: 100%;
    }
  }
  .title {
    font-size: 18px;
    position: absolute;
    left: 18px;
    bottom: 18px;
    color: #fff;
  }
  .button {
    font-size: 18px;
    position: absolute;
    left: 12px;
    top: 12px;
    color: #fff;
  }
}

.musicList {
  background-color: #fff;
  width: 100%;
  border-radius: 7px;
  position: relative;
  top: -7px;
  padding-bottom: 50px;
  dt {
    height: 36px;
    line-height: 36px;
    font-size: 16px;
    color: #454747;
    border-bottom: 1px solid #e3e3e3;
    span {
      font-size: 14px;
      color: #797b7a;
    }
    i {
      width: 44px;
      text-align: center;
      display: inline-block;
    }
  }
  dd {
    border-bottom: 1px solid #e3e3e3;
    height: 53px;
    display: flex;
    h1 {
      flex: 0 0 44px;
      line-height: 53px;
      text-align: center;
      font-size: 16px;
      color: #6d6e6e;
    }
    .info {
      flex: 1;
      width: calc(100% - 44px);
      h2 {
        font-size: 16px;
        color: #1b1c1c;
        margin-top: 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      h3 {
        font-size: 12px;
        color: #929393;
      }
    }
    .redPlay{
      width: 30px;
      height: 30px;
      // background-color: red;
      margin-right: 10px;
      display: flex;
      margin-top: 4px;
      align-items: flex-end;
      div{
        animation: playNow 0.6s linear infinite alternate;
         width: 6px;
        height: 30px;
        background-color: red;
          animation-play-state: paused;

      }
      &.animationRunning{
        div {
          animation-play-state: running;
        }
      }
     
      .short{
       
        margin-right: 4px;
        
      }
       .middle{
       
        margin-right: 4px;
        animation-delay: -0.6s;
      }
       .long{
       
        animation-delay: -0.3s;
      }
    }
  }
}
</style>